Spot-On
spot-on-starbeam-reader.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef _spoton_starbeam_reader_h_
29 #define _spoton_starbeam_reader_h_
30 
31 #include <QFuture>
32 #include <QHash>
33 #include <QObject>
34 #include <QSqlDatabase>
35 #include <QTimer>
36 
37 class spoton_crypt;
38 
39 class spoton_starbeam_reader: public QObject
40 {
41  Q_OBJECT
42 
43  public:
44  spoton_starbeam_reader(const qint64 id,
45  const double readInterval,
46  QObject *parent);
48  qint64 id(void) const;
49  void setReadInterval(const double readInterval);
50 
51  private:
52  QFuture<QPair<QByteArray, qint64> > m_readFuture;
53  QList<QByteArray> m_magnets;
54  QString m_fileName;
55  QTimer m_etaTimer;
56  QTimer m_expiredResponse;
57  QTimer m_timer;
58  bool m_fragmented;
59  bool m_ultra;
60  double m_readInterval;
61  int m_neighborIndex;
62  int m_stalled;
63  qint64 m_id;
64  qint64 m_position;
65  qint64 m_previousPosition;
66  qint64 m_rate;
67  qint64 m_rc;
68  qint64 m_time0;
69  QByteArray eta(void);
70  QHash<QString, QByteArray> elementsFromMagnet(const QByteArray &magnet,
71  spoton_crypt *crypt);
72  QPair<QByteArray, qint64> read(const QString &fileName,
73  const QString &pulseSize,
74  const qint64 position);
75  void populateMagnets(const QSqlDatabase &db);
76  void pulsate(const QByteArray &buffer,
77  const QString &fileName,
78  const QString &pulseSize,
79  const QString &fileSize,
80  const QByteArray &magnet,
81  const QByteArray &nova,
82  const QByteArray &hash,
83  const QByteArray &sha3_512_hash,
84  const qint64 rc,
85  spoton_crypt *crypt);
86  void savePositionAndStatus(const QString &status);
87 
88  private slots:
89  void slotAcknowledgePosition(const qint64 id, const qint64 position);
90  void slotETATimerTimeout(void);
91  void slotExpiredResponseTimeout(void);
92  void slotTimeout(void);
93 };
94 
95 #endif
spoton_starbeam_reader
Definition: spot-on-starbeam-reader.h:39
spoton_crypt
Definition: spot-on-crypt.h:64